package cn.edu.zafu.bigdata.YinMingyan.chapter05;

import java.util.HashMap;

/**
 * Manages student grades using a HashMap.
 */
public class StudentGradeManager {
    private HashMap<String, Integer> studentGrades;

    /**
     * Constructs a StudentGradeManager with an empty HashMap.
     */
    public StudentGradeManager() {
        studentGrades = new HashMap<>();
    }

    /**
     * Adds or updates a student's grade.
     *
     * @param name  the student's name
     * @param grade the student's grade
     */
    public void addStudent(String name, int grade) {
        studentGrades.put(name, grade);
    }

    /**
     * Retrieves a student's grade.
     *
     * @param name the student's name
     * @return the student's grade, or -1 if the student does not exist
     */
    public int getGrade(String name) {
        return studentGrades.getOrDefault(name, -1);
    }

    /**
     * Removes a student's grade.
     *
     * @param name the student's name
     */
    public void removeStudent(String name) {
        studentGrades.remove(name);
    }
}
